// pages/sl/sl.js
const { getData, getOrderBy, getGwcs } = require('../../http/api')
import Toast from '../../miniprogram_npm/@vant/weapp/toast/toast';

Page({

  /**
   * 页面的初始数据
   */
  data: {
    fff: false,
    searchValue: '',
    index: 0,
    list: [],
    list1: [],
    flag: false,
    currentIndex: 0,
    "firstList": [{ name: 'w券1', money: '5.00' }, { name: 'w券2', money: '50.00' }],
    "secondList": [{ name: 'y券1', money: '10.00' }, { name: 'y券2', money: '20.00' }],
    "thirdList": [{ name: 'g券1', money: '30.00' }, { name: 'g券2', money: '40.00' }],
    "forthList": [{ name: 'f券1', money: '60.00' }, { name: 'g券2', money: '80.00' }],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // this.searchSubmit()
    // console.log(options.val);
    this.setData({
      searchValue: options.val
    })
    this.setData({
    })


  },

  ghq_blur() {
    // console.log(this.data.searchValue);
    getData().then(res => {
      // console.log(res.data.data);
      let arr = res.data.data;

      // console.log(arr);
      this.data.list = arr.filter(item => {
        return item.name.includes(this.data.searchValue);
        // return item.name == this.data.data.searchValue;
      })
      this.setData({
        list: this.data.list
      })
      console.log(this.data.list);
      // console.log(this.data.list)
      // console.log(arrs);
    })
  },
  searchSubmit(e) {
    getData().then(res => {
      let val = e.detail.value
      let arr = res.data.data
      this.data.list = JSON.parse(JSON.stringify(arr))
      this.data.list = arr.filter(ele => {
        return ele.name.includes(val)
      })
      this.setData({
        list: this.data.list
      })
    })

  },

  paths(e) {
    console.log(e.currentTarget.dataset.id);
    wx.navigateTo({
      url: '/pages/search/search',
    })
  },
  setPrice(e) {
    getOrderBy(e.currentTarget.dataset.idx, wx.getStorageSync('token')).then(res => {
      console.log(res.data.data);
      this.setData({
        list: res.data.data,
        index: e.currentTarget.dataset.index
      })
    })

  },
  all(e) {
    this.setData({
      index: e.currentTarget.dataset.index
    })
    this.ghq_blur()
  },
  title_ticket(e) {
    getOrderBy(e.currentTarget.dataset.idx, wx.getStorageSync('token')).then(res => {
      console.log(res.data.data);
      this.setData({
        list: res.data.data,
        index: e.currentTarget.dataset.index
      })
    })
  },

  setSell(e) {
    getOrderBy(e.currentTarget.dataset.idx, wx.getStorageSync('token')).then(res => {
      console.log(res.data.data);
      this.setData({
        list: res.data.data,
        index: e.currentTarget.dataset.index
      })
    })
  },


  pagechange: function (e) {
    if ("touch" === e.detail.source) {
      let currentPageIndex = this.data.currentIndex
      currentPageIndex = (currentPageIndex + 1) % 3
      this.setData({
        currentIndex: currentPageIndex
      })
    }
  },

  titleClick: function (e) {
    let currentPageIndex =
      this.setData({
        //拿到当前索引并动态改变
        currentIndex: e.currentTarget.dataset.idx
      })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.ghq_blur()
  },

  abab(e) {
    getGwcs(wx.getStorageSync('token'), e.detail).then(res => {
      console.log(res);
      Toast.success('加入成功');
    })
    this.setData({
      ID: e.detail,
    })
  },
  tab() {
    this.setData({
      fff:!this.data.fff
    })
    console.log(this.data.fff);
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})